﻿package {
	import flash.display.*;
	import flash.events.TimerEvent;
	import flash.events.MouseEvent;
	import flash.utils.Timer;
	class llkBG extends Sprite {
		private var mc:Array=new Array();
		private var total:uint=10;
		private var bgTimer:Timer;
		private var homeTimer:Timer;
		private var bigBg:BigBG;
		public function llkBG():void {
			bigBg=new BigBG;
			bigBg.tree1.x+=Math.random()*20-10;
			bigBg.tree1.y+=Math.random()*10-5;
			bigBg.house1.x+=Math.random()*20-10;
			bigBg.house1.y+=Math.random()*10-5;
			bigBg.house2.x+=Math.random()*20-10;
			bigBg.house2.y+=Math.random()*10-5;
			addChild(bigBg);
			bigBg.home.addEventListener(MouseEvent.CLICK,homeclick);
			bigBg.home.addEventListener(MouseEvent.ROLL_OUT,homeout);
			bigBg.house1.addEventListener(MouseEvent.CLICK,houseclick);
			bigBg.house2.addEventListener(MouseEvent.CLICK,houseclick);
			var n:uint;
			var i:int;
			for (i=0; i<total; i++) {
				mc[i]=new TwoIcons();
				//mc[i].iconbg.alpha=0;
				n=Math.floor(Math.random()*21)+1;
				mc[i].gotoAndStop(n);
				addChild(mc[i]);
			}
			setloc();
			set3D();
			bgTimer=new Timer(10);
			bgTimer.addEventListener(TimerEvent.TIMER,ontime);
			//this.addEventListener(MouseEvent.CLICK,onclick);
			bgTimer.start();
			homeTimer=new Timer(10);
			homeTimer.addEventListener(TimerEvent.TIMER,hometime);
		}
		private function houseclick(e:MouseEvent):void {		
			var housemc:MovieClip=e.target;
			housemc.light.alpha=housemc.light.alpha==0?1:0;
		}
		private function homeclick(e:MouseEvent):void {		
			homeTimer.start();
		}
		private function homeout(e:MouseEvent):void{
			bigBg.email.alpha=0;
			homeTimer.stop();
		}
		private function hometime(e:TimerEvent):void{
			if(bigBg.email.alpha<1)bigBg.email.alpha+=.05;
		}
		private function ontime(e:TimerEvent) {
			var t:MovieClip;
			for (i=0; i<total; i++) {
				t=mc[i];
				t.rotationX+=1;
				t.rotationY+=1;
				t.x++;
				t.y+=.5;
				if (t.x<0||t.x>550) {
					t.x=0;
				}
				if (t.y<0||t.y>400) {
					t.y=0;
				}
			}
		}
		private function setloc():void {
			var t:MovieClip;
			for (i=0; i<total; i++) {
				t=mc[i];
				t.alpha=(Math.random()*.3);
				t.scaleX=.3;
				t.scaleY=.3;
				t.x=(Math.random()*500);
				t.y=(Math.random()*350);
			}
		}
		private function set3D():void {
			var t:MovieClip;
			for (i=0; i<total; i++) {
				t=mc[i];
				t.rotationX=(Math.random()*360);
				t.rotationY=(Math.random()*360);
				t.z=(Math.random()*20);
			}

		}
	}
}